# =============================================================================
# KinectFeedDisplay - v0.0.1
# =============================================================================

cmake_minimum_required(VERSION 2.6)

# ==[ Project Settings ]=======================================================

project(KinectFeedDisplay)

# Version
set(KinectFeedDisplay_VERSION_MAJOR 0)
set(KinectFeedDisplay_VERSION_MINOR 1)

# ==[ Add CMAKE Module Paths ]=================================================

# Ogre / OIS
if(EXISTS "/usr/local/lib/OGRE/cmake")
    set(CMAKE_MODULE_PATH "/usr/local/lib/OGRE/cmake/;${CMAKE_MODULE_PATH}")
    set(OGRE_SAMPLES_INCLUDEPATH "/usr/local/share/OGRE/samples/Common/include/")
elseif(EXISTS "/usr/lib/OGRE/cmake")
    set(CMAKE_MODULE_PATH "/usr/lib/OGRE/cmake/;${CMAKE_MODULE_PATH}")
    set(OGRE_SAMPLES_INCLUDEPATH "/usr/share/OGRE/samples/Common/include/")
else ()
    message(SEND_ERROR "Failed to find module path.")
endif(EXISTS "/usr/local/lib/OGRE/cmake")

# ==[ Find Required Packages ]=================================================

find_package(PkgConfig REQUIRED)

if(NOT PKG_CONFIG_FOUND)
    message(SEND_ERROR "Failed to find PkgConfig")
endif()

# ----

pkg_check_modules(FREENECT REQUIRED libfreenect)

if(NOT FREENECT_FOUND)
    message(SEND_ERROR "Failed to find libfreenect")
endif()

# ----

find_package(OGRE REQUIRED)

if(NOT "${OGRE_VERSION_NAME}" STREQUAL "Cthugha")
    message(SEND_ERROR "You need Ogre 1.7 Cthugha to build this.")
endif()

# ----

find_package(OIS REQUIRED)

if(NOT OIS_FOUND)
    message(SEND_ERROR "Failed to find OIS.")
endif()

# ----

# ==[ Set Headers ]============================================================

set(HDRS
    ./Mutex.h
    ./BaseApplication.h
    ./KinectDevice.h
    ./OgreKinectApp.h
)

# ==[ Set Sources ]============================================================

set(SRCS
    ./BaseApplication.cpp
    ./KinectDevice.cpp
    ./OgreKinectApp.cpp
    ./main.cpp
)

# ==[ Include Directories ]====================================================

include_directories(
    ${OIS_INCLUDE_DIRS}
    ${OGRE_INCLUDE_DIRS}
    ${OGRE_SAMPLES_INCLUDEPATH}
    ${FREENECT_INCLUDE_DIRS}
    ${PROJECT_BINARY_DIR}
)

# ==[ Create Executable ]======================================================

add_executable(KinectFeedDisplay ${HDRS} ${SRCS})

# ==[ Linking & Properties ]===================================================

set_target_properties(KinectFeedDisplay PROPERTIES DEBUG_POSTFIX _d)
target_link_libraries(KinectFeedDisplay ${OGRE_LIBRARIES} ${OIS_LIBRARIES} ${FREENECT_LIBRARIES})

# ==[ Set Output Directories ]=================================================

file(MAKE_DIRECTORY ${PROJECT_SOURCE_DIR}/dist/bin)
file(MAKE_DIRECTORY ${PROJECT_SOURCE_DIR}/dist/media)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/dist/bin)

install(TARGETS KinectFeedDisplay
    RUNTIME DESTINATION bin
    CONFIGURATIONS All)
 
install(DIRECTORY ${PROJECT_SOURCE_DIR}/dist/media
    DESTINATION ./
    CONFIGURATIONS Release RelWithDebInfo Debug
)
 
install(FILES ${PROJECT_SOURCE_DIR}/dist/bin/plugins.cfg
    ${PROJECT_SOURCE_DIR}/dist/bin/resources.cfg
    DESTINATION bin
    CONFIGURATIONS Release RelWithDebInfo Debug
)

# ==[ Find Required Packages ]=================================================

# std C libs
#find_package(stdlibs REQUIRED)

# pthread
#find_package(pthread REQUIRED)

# OGRE
#find_package(OGRE REQUIRED)

# OIS
#find_package(OIS REQUIRED)

# libfreenect
#find_package(libfreenect REQUIRED)

# ==[ Additional Compiler Flags ]==============================================

#add_definitions(-Wall)



# ==[ Other Documentation Files ]==============================================
# TODO
